function [spectrum,corrfactor] = sabscorrect(x,y,e0,samname,alpha,tth,samthick) 

%function [spectrum,corrfactor] = sabscorrect(x,y,e0,samname,alpha,tth,samthick) 
% to correct for self absorption in the sample

%INPUT: x = x-vector
%       y = y-vector
%       e0= analyzer energy
%  samname= name of sample for input of mpr.m makro
%   alpha = incident angle relative to plane normal (deg)
%      tth= scattering angle [deg two theta]
% samthick= thickness of the sample (mm)
%OUTPUT: spectrum   = corrected spectrum
%        corrfactor = correction factor 

%depends on mpr.m, abscorr2.m

mu_i = mpr(x*1e-03+e0,samname);
mu_f = mpr(e0,samname);

alpha_r = 90 - alpha;
beta_r  = 90 - (tth - alpha_r);
l = samthick*1e-01;
corrfactor = abscorr2(mu_i,mu_f,alpha_r,beta_r,l);

spectrum = corrfactor.*y;
